package com.fi.recogn.util;

import cn.hutool.core.util.StrUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;

import static com.fi.recogn.util.FileTypeUtil.FileType.HTML;
import static com.fi.recogn.util.FileTypeUtil.FileType.EXCEL;
import static com.fi.recogn.util.FileTypeUtil.FileType.WORD;

/**
 * @Description TODO
 * @Author lujiahong
 * @Date 2024/8/12 14:26
 */
public class FileTypeUtil {

    @Getter
    @AllArgsConstructor
    public enum FileType {
        WORD(Arrays.asList("doc", "docx")),
        EXCEL(Arrays.asList("xls", "xlsx")),
        HTML(Arrays.asList("htm", "html")),
        OTHRT(null);
        private final List<String> suffixes;
    }

    public static FileType ofFileTypeOrDefaultWord(String fileExt){
        return ofFileTypeOrDefault(fileExt, WORD);
    }

    public static FileType ofFileTypeOrDefault(String fileExt, FileType fileType){
        if(StrUtil.isEmpty(fileExt))return fileType;
        if(isWord(fileExt))return WORD;
        if(isExcel(fileExt))return EXCEL;
        if(isHtmls(fileExt))return HTML;
        return fileType;
    }

    public static boolean isWord(String fileExt){
        if(StrUtil.isEmpty(fileExt))return false;
        return WORD.getSuffixes().contains(fileExt);
    }
    public static boolean isDoc(String fileExt){
        if(StrUtil.isEmpty(fileExt))return false;
        return WORD.getSuffixes().get(0).equals(fileExt);
    }
    public static boolean isDocx(String fileExt){
        if(StrUtil.isEmpty(fileExt))return false;
        return WORD.getSuffixes().get(1).equals(fileExt);
    }

    public static boolean isExcel(String fileExt){
        if(StrUtil.isEmpty(fileExt))return false;
        return EXCEL.getSuffixes().contains(fileExt);
    }
    public static boolean isXls(String fileExt){
        if(StrUtil.isEmpty(fileExt))return false;
        return EXCEL.getSuffixes().get(0).equals(fileExt);
    }
    public static boolean isXlsx(String fileExt){
        if(StrUtil.isEmpty(fileExt))return false;
        return EXCEL.getSuffixes().get(1).equals(fileExt);
    }

    public static boolean isHtmls(String fileExt){
        if(StrUtil.isEmpty(fileExt))return false;
        return HTML.getSuffixes().contains(fileExt);
    }
    public static boolean isHtm(String fileExt){
        if(StrUtil.isEmpty(fileExt))return false;
        return HTML.getSuffixes().get(0).equals(fileExt);
    }
    public static boolean isHtml(String fileExt){
        if(StrUtil.isEmpty(fileExt))return false;
        return HTML.getSuffixes().get(1).equals(fileExt);
    }
}